﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using System.Web;
using Antu.WorkFlowFactory;
using System.Data;
using WebSys.UI.OfficeFlow;

namespace WebSys.UI.Skins.OfficeFlow
{
    public class WorkFlowHandlerSkin : MPBasicTemplate
    {
        FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
        static string wiid, ctlId, iid, wid, userid, step, isreadonly;
        StepType stepType;
        public string UserId
        {
            get { if (base.Page.Session["UserId"] != null) { return base.Page.Session["UserId"].ToString(); } else { return string.Empty; } }
            set { base.Page.Session["UserId"] = value; }
        }
        protected override void OnLoad(EventArgs e)
        {
            LoginHelper.CheckLogin();
            MPHeader.RegistAjaxScripts(typeof(WorkFlowHandlerSkin));
            InitControl();
            base.OnLoad(e);
            if (!base.Page.IsPostBack)
            {
                Initcy();
            }
        }
        private void InitControl()
        {
            isreadonly = base.Page.Request["readonly"];
            wiid = base.Page.Request["wiid"];
            //ctlId = base.Page.Request["ctlid"];
            ctlId = HttpContext.Current.Server.UrlDecode(base.Page.Request["CTLID"]);
            iid = base.Page.Request["iid"];
            wid = _FlowFactoryProvider.GetWidByIID(iid);
            userid = UserId;
            step = _FlowFactoryProvider.GetStepName(ctlId, wid);

            if (!string.IsNullOrEmpty(isreadonly) && isreadonly.ToLower() == "true")
            {
            }
            else
            {
                //bool canopen = _FlowFactoryProvider.CanOpen(userid, iid, wiid, step);
                //bool isopen = _FlowFactoryProvider.IsOpen(iid, wiid, step);
                string msg = "";
                if (false == _FlowFactoryProvider.TaskOpenCheck(iid, wiid, step, userid, out msg))
                {
                    Antu.Utilities.UtilitiesPage.AlertDialogClear("alert('" + msg + "！');", "window.close();");
                    return;
                }
                //if (!canopen || isopen)
                //{
                //    Antu.Utilities.UtilitiesPage.AlertDialogClear("该业务已被处理或无权限处理！", "window.close();");
                //    return;
                //}
                else
                {
                    stepType = _FlowFactoryProvider.GetStepTypeByStep(wid, ctlId);
                    if (stepType != StepType.MutiFlowEnd)//多流向结束岗位不可设置
                    {
                        _FlowFactoryProvider.SetOpened(userid, iid, wiid, step);
                    }
                }
            }
        }
        private void Initcy()
        {

        }
        [Antu.Core.Ajax.AjaxMethod()]
        public static string getRemark(string iid, string wiid, string ctlId, string isreadonly, string isback)
        {
            FlowFactoryProvider _FlowFactoryProvider1 = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
            if (!string.IsNullOrEmpty(isreadonly) && isreadonly.ToLower() == "true")
            {
                return null;
            }
            else
            {
                string msg = "";
                if (false == _FlowFactoryProvider1.TaskOpenCheck(iid, wiid, step, userid, out msg))
                {
                    return null;
                }
                else
                {
                    if (!string.IsNullOrEmpty(isback))
                    {
                        if (isback == "1")
                        {
                            string sql = "Select remark From st_work_item Where iid='" + iid + "' and wiid='" + wiid + "' and STEPCTLID='" + ctlId + "'";
                            string strRemak = _FlowFactoryProvider1.GetStr(sql);
                            return strRemak;
                        }
                        return null;
                    }
                    return null;
                }
            }
        }
        [Antu.Core.Ajax.AjaxMethod()]
        public static string gettree(string iid, string wiid, string ctlId, string isreadonly)
        {
            FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
            string sqlstr = "SELECT Wid FROM St_Instance WHERE iid='" + iid + "'";
            string wid = _FlowFactoryProvider.GetStr(sqlstr);
            string userid = HttpContext.Current.Session["UserID"].ToString();
            string strTree = string.Empty;
            DataTable dt, dt3, dt4, dt5, dt6, dt7, dt8;
            dt = _FlowFactoryProvider.GetDT(gsql(" And 级数=0 "));
            if (dt.Rows.Count > 0)
            {
                strTree = "indexdata = [";
                #region 0
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string strType = dt.Rows[i]["TYPE"].ToString();
                    string strPath = dt.Rows[i]["path"].ToString();
                    string strJS = dt.Rows[i]["级数"].ToString();

                    if (strType == "0")
                    {
                        strTree += "{ text: '" + GetName(strPath) + "', isexpand: false, children: [";
                    }
                    dt3 = _FlowFactoryProvider.GetDT(gsql(" And 级数=1 And Path like '%" + dt.Rows[i]["path"].ToString() + "%'"));
                    if (dt3.Rows.Count > 0)
                    {
                        for (int k = 0; k < dt3.Rows.Count; k++)
                        {
                            #region 1
                            if (dt3.Rows[k]["TYPE"].ToString() == "0")
                            {
                                strTree += "{ text: '" + GetName(dt3.Rows[k]["path"].ToString()) + "', isexpand: false, children: [";
                            }
                            dt4 = _FlowFactoryProvider.GetDT(gsql(" And 级数=2 And Path like '%" + dt3.Rows[k]["path"].ToString() + "%'"));
                            if (dt4.Rows.Count > 0)
                            {
                                #region 2
                                for (int m = 0; m < dt4.Rows.Count; m++)
                                {
                                    if (dt4.Rows[m]["TYPE"].ToString() == "0")
                                    {
                                        strTree += "{ text: '" + GetName(dt4.Rows[m]["path"].ToString()) + "', isexpand: false, children: [";
                                    }
                                    dt5 = _FlowFactoryProvider.GetDT(gsql(" And 级数=3 And Path like '%" + dt4.Rows[m]["path"].ToString() + "%'"));
                                    if (dt5.Rows.Count > 0)
                                    {
                                        #region 3
                                        for (int n = 0; n < dt5.Rows.Count; n++)
                                        {
                                            if (dt5.Rows[n]["TYPE"].ToString() == "0")
                                            {
                                                strTree += "{ text: '" + GetName(dt5.Rows[n]["path"].ToString()) + "', isexpand: false, children: [";
                                            }
                                            dt6 = _FlowFactoryProvider.GetDT(gsql(" And 级数=4 And Path like '%" + dt5.Rows[n]["path"].ToString() + "%' "));
                                            if (dt6.Rows.Count > 0)
                                            {
                                                #region 4
                                                for (int p = 0; p < dt6.Rows.Count; p++)
                                                {
                                                    if (dt6.Rows[p]["TYPE"].ToString() == "0")
                                                    {
                                                        strTree += "{ text: '" + GetName(dt6.Rows[p]["path"].ToString()) + "', isexpand: false, children: []}";
                                                    }
                                                    dt7 = _FlowFactoryProvider.GetDT(gsql(" And 级数=5 And Path like '%" + dt6.Rows[p]["path"].ToString() + "%' "));
                                                    if (dt7.Rows.Count > 0)
                                                    {
                                                        #region 5
                                                        for (int q = 0; q < dt7.Rows.Count; q++)
                                                        {
                                                            if (dt7.Rows[q]["TYPE"].ToString() == "0")
                                                            {
                                                                strTree += "{ text: '" + GetName(dt7.Rows[q]["path"].ToString()) + "', isexpand: false, children: []}";
                                                            }
                                                            dt8 = _FlowFactoryProvider.GetDT(gsql(" And 级数=6 And Path like '%" + dt7.Rows[q]["path"].ToString() + "%' "));
                                                            if (dt8.Rows.Count > 0)
                                                            {
                                                                #region 6
                                                                for (int r = 0; r < dt8.Rows.Count; r++)
                                                                {
                                                                    if (dt8.Rows[r]["TYPE"].ToString() == "0")
                                                                    {
                                                                        strTree += "{ text: '" + GetName(dt8.Rows[r]["path"].ToString()) + "', isexpand: false, children: []}";
                                                                    }
                                                                    else
                                                                    {
                                                                        strTree += GetTypeStr(dt8.Rows[r]["PATH"].ToString(), dt8.Rows[r]["TYPE"].ToString(), GetName(dt8.Rows[r]["PATH"].ToString()), geturltran(dt8.Rows[r]["RES_VALUE"].ToString()), dt8.Rows[r]["RTID"].ToString());
                                                                    }
                                                                    strTree += ",";
                                                                }
                                                                if (strTree.EndsWith(",")) { strTree = strTree.Substring(0, strTree.Length - 1); }
                                                                #endregion
                                                            }
                                                            if (dt7.Rows[q]["TYPE"].ToString() == "0")
                                                            {
                                                                strTree += "]}";
                                                            }
                                                            else
                                                            {
                                                                strTree += GetTypeStr(dt7.Rows[q]["PATH"].ToString(), dt7.Rows[q]["TYPE"].ToString(), GetName(dt7.Rows[q]["PATH"].ToString()), geturltran(dt7.Rows[q]["RES_VALUE"].ToString()), dt7.Rows[q]["RTID"].ToString());
                                                            }
                                                            strTree += ",";
                                                        }
                                                        if (strTree.EndsWith(",")) { strTree = strTree.Substring(0, strTree.Length - 1); }
                                                        #endregion
                                                    }
                                                    if (dt6.Rows[p]["TYPE"].ToString() == "0")
                                                    {
                                                        strTree += "]}";
                                                    }
                                                    else
                                                    {
                                                        strTree += GetTypeStr(dt6.Rows[p]["PATH"].ToString(), dt6.Rows[p]["TYPE"].ToString(), GetName(dt6.Rows[p]["PATH"].ToString()), geturltran(dt6.Rows[p]["RES_VALUE"].ToString()), dt6.Rows[p]["RTID"].ToString());
                                                    }
                                                    strTree += ",";
                                                }
                                                if (strTree.EndsWith(",")) { strTree = strTree.Substring(0, strTree.Length - 1); }
                                                #endregion
                                            }
                                            if (dt5.Rows[n]["TYPE"].ToString() == "0")
                                            {
                                                strTree += "]}";
                                            }
                                            else
                                            {
                                                strTree += GetTypeStr(dt5.Rows[n]["PATH"].ToString(), dt5.Rows[n]["TYPE"].ToString(), GetName(dt5.Rows[n]["PATH"].ToString()), geturltran(dt5.Rows[n]["RES_VALUE"].ToString()), dt5.Rows[n]["RTID"].ToString());
                                            }
                                            strTree += ",";

                                        }
                                        if (strTree.EndsWith(",")) { strTree = strTree.Substring(0, strTree.Length - 1); }
                                        #endregion
                                    }
                                    if (dt4.Rows[m]["TYPE"].ToString() == "0")
                                    {
                                        strTree += "]}";
                                    }
                                    else
                                    {
                                        strTree += GetTypeStr(dt4.Rows[m]["PATH"].ToString(), dt4.Rows[m]["TYPE"].ToString(), GetName(dt4.Rows[m]["PATH"].ToString()), geturltran(dt4.Rows[m]["RES_VALUE"].ToString()), dt4.Rows[m]["RTID"].ToString());
                                    }
                                    strTree += ",";
                                }
                                if (strTree.EndsWith(",")) { strTree = strTree.Substring(0, strTree.Length - 1); }
                                #endregion
                            }
                            if (dt3.Rows[k]["TYPE"].ToString() == "0")
                            {
                                strTree += "]}";
                            }
                            else
                            {
                                strTree += GetTypeStr(dt3.Rows[k]["PATH"].ToString(), dt3.Rows[k]["TYPE"].ToString(), GetName(dt3.Rows[k]["PATH"].ToString()), geturltran(dt3.Rows[k]["RES_VALUE"].ToString()), dt3.Rows[k]["RTID"].ToString());
                            }
                            strTree += ",";
                            #endregion
                        }
                        if (strTree.EndsWith(",")) { strTree = strTree.Substring(0, strTree.Length - 1); }
                    }
                    if (strType == "0")
                    {
                        strTree += "]}";
                    }
                    else
                    {
                        strTree += GetTypeStr(dt.Rows[i]["PATH"].ToString(), dt.Rows[i]["TYPE"].ToString(), GetName(dt.Rows[i]["PATH"].ToString()), geturltran(dt.Rows[i]["RES_VALUE"].ToString()), dt.Rows[i]["RTID"].ToString());
                    }
                    strTree += ",";
                }
                #endregion
                if (strTree.EndsWith(",")) { strTree = strTree.Substring(0, strTree.Length - 1); }
                strTree += "];";
            }
            return strTree;
        }
        #region 资源树

        protected static string GetTypeStr(string path, string type, string name, string resvalue, string rtid)
        {
            FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
            string resid = type + "_" + path.ToString().Replace("/", "_");
            string getStr = string.Empty;
            if (type == "1")
            {
                getStr = "{resid:'" + resid + "',icon:'../../Themes/Default/Images/Icons/ie.gif',url:'" + geturltran(resvalue) + "',text:'" + name + "'}";
            }
            else if (type == "2")
            {
                string sql = "Select lower(ext_name) ext_name From st_attachment Where aid='" + resvalue + "'";
                string extname = _FlowFactoryProvider.GetStr(sql);
                string picurl = "globe.gif";//根据类型组织图标
                switch (extname.ToLower())
                {
                    case ".gif":
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                    case ".bmp":
                        picurl = "img.gif";
                        break;
                    case ".doc":
                        picurl = "word.gif";
                        break;
                    case ".xls":
                        picurl = "excel.gif";
                        break;
                    case ".pdf":
                        picurl = "pdf.jpg";
                        break;
                }

                string url = "WorkFlowResource.aspx?iid=" + iid + "&ctlId=" + ctlId + "&wid=" + wid + "&wiid=" + wiid + "&aid=" + resvalue + "&extname=" + extname.ToLower();
                getStr = "{resid:'" + resid + "',icon:'../../Themes/Default/Images/Icons/" + picurl + "',url:'" + url + "',text:'" + name + "'}";

            }
            else if (type == "3")
            {
                string textstyle = "";
                string url = System.Configuration.ConfigurationManager.AppSettings["WorkFlowService"] + "HtmlPage/HtmlMainPage.aspx?";
                if (!string.IsNullOrEmpty(isreadonly) && isreadonly.ToLower() == "true")
                {
                    url += "readonly=true&";
                }
                else
                {
                    if (_FlowFactoryProvider.CheckTableRight(iid, wid, ctlId, rtid, resvalue, userid))
                    {
                        textstyle = "textstyle:'color:green;font-weight:bold;',";
                    }
                }
                getStr = "{resid:'" + resid + "'," + textstyle + "icon:'../../Themes/Default/Images/Icons/page.gif',url:'" + url + @"iid=" + iid
                    + @"&step='+escape('" + ctlId + "')+'&userid=" + userid + @"&rtid=" + rtid + "&formname=" + resvalue + @"&input_index=0',text:'" + name + "'}";
            }
            else
            {
                getStr = "{url:'" + geturltran(resvalue) + "',text:'" + name + "'}";
            }
            return getStr;
        }

        protected static string gsql(string strWhere)
        {
            string isread = string.Empty;
            if (!string.IsNullOrEmpty(isreadonly) && isreadonly.ToLower() == "true")
            {

            }
            else
            {
                isread = string.Format(" AND rtid IN (SELECT rtid FROM st_resource_right WHERE WID='{0}' AND sctlid='{1}') ", wid, ctlId);
            }
            string sql = string.Format(@"select t.* {0}
From (SELECT Rtid,TYPE,RES_VALUE,PATH,0 input_index,orderno,(length(Path)-length(replace(Path,'/',''))) 级数
FROM st_static_resource Where WID='{1}' And SHOW=1 {2} 
Union All
SELECT rtid,TYPE,RES_VALUE,PATH,case when input_index is null then 0 else input_index end input_index,orderno,(length(Path)-length(replace(Path,'/',''))) 级数
FROM ST_DYNAMIC_RESOURCE  WHERE IID='{3}' ) t where 1=1 {4}  Order By orderno ", GetStrCS(), wid, isread, iid, strWhere);
            return sql;
        }
        protected static int GetIntCS()
        {
            FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
            int cs = 0;
            string sql1 = string.Format(@"Select max(Distinct t.级数) 最多层 From 
(Select Distinct (length(Path)-length(replace(Path,'/',''))) 级数
FROM st_static_resource WHERE WID='{0}'
And  SHOW=1  AND rtid IN (SELECT rtid FROM st_resource_right WHERE WID='{0}'
AND sctlid='{1}' ) Union All SELECT Distinct (length(Path)-length(replace(Path,'/',''))) 级数
FROM ST_DYNAMIC_RESOURCE  WHERE IID='{2}') t ", wid, ctlId, iid);
            string cs1 = _FlowFactoryProvider.GetStr(sql1);
            if (!string.IsNullOrEmpty(cs1))
            {
                cs = Convert.ToInt32(cs1);
            }
            return cs;
        }
        protected static string GetStrCS()
        {
            string strcs = string.Empty;
            //StringBuilder sbr = new StringBuilder();
            //int cs = GetIntCS();
            //for (int i = 0; i < cs; i++)
            //{
            //    sbr.Append(string.Format("regexp_substr(path,'[^/]+',1,{0}) {1}", i + 1, "目录" + (i + 1).ToString()));
            //    if (sbr.Length > 0) { sbr.Append(","); }
            //}
            //if (sbr.Length > 0) { strcs = "," + sbr.ToString().Substring(0, sbr.ToString().Length - 1); }
            return strcs;
        }

        protected static string GetName(string strPath)
        {
            string strName = string.Empty;
            string pathu = string.Empty;
            string pathf = string.Empty;
            int wz = 0;
            int fwz = 0;
            if (strPath.IndexOf("/") > -1)
            {
                wz = strPath.LastIndexOf("/");
            }
            if (wz > 0)
            {
                strName = strPath.Substring(wz + 1, strPath.Length - wz - 1);
            }
            if (string.IsNullOrEmpty(strName)) { strName = strPath; }
            return strName;
        }
        protected static string GetResValue(string strResvalue0)
        {
            string strResValue = string.Empty;
            if (strResvalue0.IndexOf("{IID}") > -1)
            {
                strResValue = strResvalue0.Replace("{IID}", string.Format("iid={0}", iid));
            }
            else if (strResvalue0.IndexOf("{STEP}") > -1)
            {
                strResValue = strResvalue0.Replace("{STEP}", string.Format("step={0}", HttpContext.Current.Server.UrlEncode(ctlId)));
            }
            else
            {
                strResValue = strResvalue0;
            }
            return strResValue;
        }
        protected static string geturlt(string oldurl)
        {
            if (oldurl.IndexOf("{IID}") > -1)
            {
                oldurl = oldurl.Replace("{IID}", "IID=" + iid);
            }
            if (oldurl.IndexOf("{WIID}") > -1)
            {
                oldurl = oldurl.Replace("{WIID}", "WIID=" + wiid);
            }
            return oldurl;
        }
        private static string geturltran(string oldurl)
        {
            if (oldurl.IndexOf("{IID}") > -1)
            {
                oldurl = oldurl.Replace("{IID}", "IID=" + iid);
            }
            if (oldurl.IndexOf("{WIID}") > -1)
            {
                oldurl = oldurl.Replace("{WIID}", "WIID=" + wiid);
            }
            return oldurl;
        }

        #endregion

        #region 旧资源树
//        public static string gettree1(string iid, string wiid, string ctlId, string isreadonly)
//        {
//            string wid = _FlowFactoryProvider.GetWidByIID(iid);
//            string userid = HttpContext.Current.Session["UserID"].ToString();

//            DataTable dt = new DataTable();
//            if (!string.IsNullOrEmpty(isreadonly) && isreadonly.ToLower() == "true")
//            {
//                dt = wfr.ListInstanceResource(iid);
//            }
//            else
//            {
//                dt = wfr.ListInstanceStepResource(wiid, ctlId, iid);
//            }
//            dt.Columns.Add(new DataColumn("ParentId"));
//            dt.Columns.Add(new DataColumn("Site"));
//            dt.Columns.Add(new DataColumn("Name"));
//            for (int i = 0; i < dt.Rows.Count; i++)
//            {
//                string path = dt.Rows[i]["Path"].ToString();
//                string[] tmps = path.Split('/');
//                dt.Rows[i]["Site"] = i + 1;
//                if (tmps.Length > 1)//不是顶节点
//                {
//                    dt.Rows[i]["Name"] = tmps[tmps.Length - 1];
//                    string pre = path.Substring(0, path.LastIndexOf('/'));
//                    DataRow[] drs = dt.Select("Path='" + pre + "'");
//                    if (drs.Length > 0)
//                        dt.Rows[i]["ParentId"] = drs[0]["Site"].ToString();
//                }
//                else
//                {
//                    dt.Rows[i]["Name"] = dt.Rows[i]["Path"].ToString();
//                    dt.Rows[i]["ParentId"] = 0;
//                }
//            }

//            string str = @"indexdata = [
//            { resid:'0',isexpand: 'true',icon:'" + Antu.Core.Components.SiteSettings.DefaultSiteSettings.ThemeFolderMapPath + @"Default/Images/Icons/globe.gif', text: '所有资源', children: [
//            " + gettreestr1(dt, "0", iid, wiid, wid, ctlId, userid, isreadonly) + @"
//            ]}];";
//            return str;
//        }
//        private static string geturltran1(string oldurl)
//        {
//            if (oldurl.IndexOf("{IID}") > -1)
//            {
//                oldurl = oldurl.Replace("{IID}", "IID=" + iid);
//            }
//            if (oldurl.IndexOf("{WIID}") > -1)
//            {
//                oldurl = oldurl.Replace("{WIID}", "WIID=" + wiid);
//            }
//            return oldurl;
//        }
//        private static string gettreestr1(DataTable dt, string nodeid, string iid, string wiid, string wid, string ctlId, string userid, string isreadonly)
//        {
//            StringBuilder sb = new StringBuilder();
//            DataRow[] drs = dt.Select("ParentId=" + nodeid);
//            for (int i = 0; i < drs.Length; i++)
//            {
//                string str = "";
//                string textstyle = "";
//                string resid = "";
//                DataRow dr = drs[i];
//                resid = dr["type"] + "_" + dr["Path"].ToString().Replace("/", "_");
//                if (dr["type"].ToString() != "0")//非目录
//                {
//                    if (dr["type"].ToString() == "3")//表单
//                    {
//                        string url = System.Configuration.ConfigurationManager.AppSettings["WorkFlowService"] + "HtmlPage/HtmlMainPage.aspx?";
//                        if (!string.IsNullOrEmpty(isreadonly) && isreadonly.ToLower() == "true")
//                        {
//                            url += "readonly=true&";
//                        }
//                        else
//                        {
//                            if (WorkFlow.CheckTableRight(iid, wid, ctlId, dr["rtid"].ToString(), dr["res_value"].ToString(), userid))
//                            {
//                                textstyle = "textstyle:'color:green;font-weight:bold;',";
//                            }
//                        }

//                        str = "{resid:'" + resid + "'," + textstyle + "icon:'" + Antu.Core.Components.SiteSettings.DefaultSiteSettings.ThemeFolderMapPath + "Default/Images/Icons/page.gif',url:'" + url + @"iid=" + iid + @"&step='+escape('" + ctlId + "')+'&userid=" + userid + @"&rtid=" + dr["rtid"] + "&formname=" + dr["res_value"] + @"&input_index=0',text:'" + dr["Name"] + "'},";
//                    }
//                    else if (dr["type"].ToString() == "1")//链接
//                    {
//                        str = "{resid:'" + resid + "',icon:'" + Antu.Core.Components.SiteSettings.DefaultSiteSettings.ThemeFolderMapPath + "Default/Images/Icons/ie.gif',url:'" + geturltran(dr["res_value"].ToString()) + "',text:'" + dr["Name"] + "'},";
//                    }
//                    else
//                    {
//                        NetoWsLib lib = new NetoWsLib();
//                        string extname = lib.GetAttachmentExtName(wid, iid, dr["path"].ToString());
//                        string picurl = "globe.gif";//根据类型组织图标
//                        switch (extname.ToLower())
//                        {
//                            case ".gif":
//                            case ".jpg":
//                            case ".jpeg":
//                            case ".png":
//                            case ".bmp":
//                                picurl = "img.gif";
//                                break;
//                            case ".doc":
//                                picurl = "word.gif";
//                                break;
//                            case ".xls":
//                                picurl = "excel.gif";
//                                break;
//                            case ".pdf":
//                                picurl = "pdf.jpg";
//                                break;
//                        }

//                        string url = "WorkFlowResource.aspx?iid=" + iid + "&ctlId=" + ctlId + "&wid=" + wid + "&wiid=" + wiid + "&aid=" + dr["res_value"] + "&extname=" + extname.ToLower();
//                        str = "{resid:'" + resid + "',icon:'" + Antu.Core.Components.SiteSettings.DefaultSiteSettings.ThemeFolderMapPath + "Default/Images/Icons/" + picurl + "',url:'" + url + "',text:'" + dr["Name"] + "'},";
//                    }
//                }
//                else//目录
//                {
//                    str = @"  {resid:'" + resid + "', isexpand: 'false', text: '" + dr["Name"] + @"', children: [ 
//                 " + gettreestr1(dt, dr["Site"].ToString(), iid, wiid, wid, ctlId, userid, isreadonly) + @"
//                        ]},";
//                }
//                sb.Append(str);
//            }
//            return sb.ToString().TrimEnd(',');
//        }
        #endregion
    }
}


